<?php

//分页 前后偏移4
class Model_Core_MultiPage{
	
	public function html_multi($page, $howpage, $purl) {
		
		$p_url = explode("?", $purl);
		if ($p_url[1] == ""){
			$purl = "?";
		}else{
			$purl = $purl."&";
		}
		$adjacents = "4";//前后偏移数
		$repage	   = "<li><a href=\"".$purl."page=".($page-1)."\">上一页</a></li>";
		$nxpage    = "<li><a href=\"".$purl."page=".($page+1)."\">下一页</a></li>";
		if ($page <= 1){
			$repage = " ";
		}
		if ($page >= $howpage){
			$nxpage = " ";
		}
		if ($page > ($adjacents + 1)) {
			$first = "<li><a href=\"".$purl."page=1"."\">1 ...</a></li>";
		}
		if ($page < ($howpage - $adjacents)){
			$last = "<li><a href=\"".$purl."page=".$howpage."\">... $howpage</a></li>";
		}
		
		$multipage = "";
		$multipage = $first;
		$multipage .= $repage;
		
		//页数过多时
		/*if (($howpage - $page) >= 10){
			$howpage = 10;
		}*/
		for ($i=1; $i<=$howpage; $i++){  //页码
			if ($page == $i){
				$multipage .= "<li><a href=\"#\" id=\"list_page_hover\">$i</a></li>";
			}elseif($page > ($i + $adjacents) || $page < ($i - $adjacents)){
				
			}else{
				$multipage .= "<li><a href=\"".$purl."page=".$i."\">$i</a></li>";
			}
		}
		$multipage .= $last;
		$multipage .= $nxpage;
		
		return $multipage;
	}

}
